package rev1;

import java.util.HashMap;

public class Node {

	int id;
	HashMap<String, String> map;
	Node nextNode;
	
	
	public Node(int id)
	{
		this.id = id;
		map =  new HashMap<String, String>();
	}
	
	
	public String get(String hsh) 
	{
		String sNodeHsh = DHTUtil.parseNodeHash(hsh);
		String sKey = DHTUtil.parseKey(hsh);
		
		if (sNodeHsh == null || sKey == null)
			throw new RuntimeException("Bad hsh in-parm");
		
		int inNodeHsh = Integer.parseInt(sNodeHsh);

		// If this is last node, look for value
		if (nextNode == null)
			return map.get(sKey);
		
		if (inNodeHsh >= id && inNodeHsh < nextNode.id)
			return map.get(sKey);
		else
			return nextNode.get(hsh);
		
	}

}
